// Serial.h 
//the file is copied from vc++ bible,
//changes made are that data from char to unsigned char
//8bit,no parity,9600 baut,2 stopbit is the default connect


#ifndef __SERIAL_H__
#define __SERIAL_H__
#include "stdafx.h"

#define FC_DTRDSR       0x01
#define FC_RTSCTS       0x02
#define FC_XONXOFF      0x04
#define ASCII_BEL       0x07
#define ASCII_BS        0x08
#define ASCII_LF        0x0A
#define ASCII_CR        0x0D
#define ASCII_XON       0x11
#define ASCII_XOFF      0x13

#include <windows.h>
#include <Winbase.h>

#define TIMEOUT_SECS			20

class CSerial
{
public:
public:
	CSerial();
	~CSerial();

	BOOL Open( BYTE nPort, DWORD nBaud,BYTE nStopBits,BYTE nParity,BYTE nDataBits);
	BOOL Close( void );
	int ReadData( void *, int );
	int SendData( unsigned char *, int );
	int SendData(char *buffer,int size);

	BOOL IsOpened( void ){ return m_bOpened; }

    BOOL Wait(DWORD timeout);
	BOOL ClearBuffers();
    void SetTimeOut(DWORD timeout);
protected:
	BOOL WriteCommByte( unsigned char );
protected:
	DWORD m_dwTimeOut;
	BOOL m_bOpened;
	HANDLE m_hIDComDev;

};
#endif

